package edu.zerl.easyexceldemo.util;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.converters.WriteConverterContext;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.baomidou.mybatisplus.annotation.IEnum;
import edu.zerl.easyexceldemo.enums.ReadingStatusEnum;
import edu.zerl.easyexceldemo.enums.WxReceiveStatusEnum;

public class BaseEnumConvert implements Converter<IEnum> {

    @Override
    public WriteCellData<?> convertToExcelData(WriteConverterContext<IEnum> context) {
        IEnum ienum = context.getValue();
        String value = "";

        if(ienum instanceof ReadingStatusEnum) {
            ReadingStatusEnum readingStatusEnum = (ReadingStatusEnum)ienum;
            value = readingStatusEnum.getDescp();
        } else if(ienum instanceof WxReceiveStatusEnum) {
            WxReceiveStatusEnum wxReceiveStatusEnum = (WxReceiveStatusEnum)ienum;
            value = wxReceiveStatusEnum.getDescp();
        }

        return new WriteCellData<>(value);

    }
}
